<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增产品入库</title>
    <script src="js/jquery-1.10.2.min.js"></script>

</head>
<body>
<p>
    产品编号：<input type="text" id="pno" name="pno" placeholder="产品编号">
</p>
<p>
    产品名：<input type="text" id="pname" name="pname" placeholder="产品名">
</p>
<p>
    生产地址：<input type="text" id="paddr" name="paddr" placeholder="生产地址">
</p>
<p>
    生产日期：<input type="text" id="pdate" name="pdate" placeholder="生产日期">
</p>
<p>
    入库日期：<input type="text" id="enterdate" name="enterdate" placeholder="入库日期">
</p>
<p>
    入库数量：<input type="text" id="pnumber" name="pnumber" placeholder="入库数量">
</p>
<p>
    <input type="button" id="commit" value="新增入库">
</p>
<script type="text/javascript">
    var btn =document.getElementById("commit");
    btn.onclick = function () {
        //1. 获取请求的数据
        var pno = document.getElementById("pno").value;
        var pname = document.getElementById("pname").value;
        var paddr = document.getElementById("paddr").value;
        var pdate = document.getElementById("pdate").value;
        var enterdate = document.getElementById("enterdate").value;
        var pnumber = document.getElementById("pnumber").value;
        //json对象
        var reqData = {
            "pno":pno,
            "pname":pname,
            "paddr":paddr,
            "pdate":pdate,
            "enterdate":enterdate,
            "pnumber":pnumber,
        };
        //2.构建请求参数
        var config= {
            method:"post",
            url:"/product",
            dataType:"json",
            data:JSON.stringify(reqData),
            contentType:"application/json",
            success:function (resp) {
                //接受服务器返回的数据
                console.log(resp);
                if(resp.code ===2101){
                    window.location = "index.html";
                }else if(resp === 2102){
                    alert(resp.msg)
                }
            }
        };
        //3.发起请求
        $.ajax(config);
    };
</script>
</body>
</html>